package com.gc.db;

import java.io.Serializable;

public class Columns implements Serializable {
	private String cname; //数据库列名
	private String name; //经过转换后的属性名称
	private String type;  //与数据库列对应的java的封装数据类型
	private String bigName;   //用于封装的getset方法名称
	private String typeName; //数据库列的数据类型
	private String typeNum;//列的数据类型对应的标识
	private Integer status=0; //标识是否是主键


	public Columns(){}
	public Columns(String cname, String typeNum,String typeName) {
		this.cname = cname;
		this.typeName=typeName;
		this.typeNum=typeNum;
	}
	
	public String getBigName() {
		String first = (this.getName().charAt(0)+"").toUpperCase();
		String last = this.getName().substring(1);
		return first+last;
	}
	public void setBigName(String bigName) {
		this.bigName = bigName;
	}
	
	public String getName() {
		String fieldName = "";
		try {
			if(this.cname.indexOf("_")!=-1){
				String[] namewords = this.cname.split("_");
				for(int i=0;i<namewords.length;i++){
					if(i==0){
						fieldName+=namewords[0].toLowerCase();
					}else{
						String first = (namewords[i].charAt(0)+"").toUpperCase();
						String last = namewords[i].substring(1).toLowerCase();
						fieldName+=first+last;
					}
				}
			}else{
				String first = (cname.charAt(0)+"").toLowerCase();
				String last = cname.substring(1);
				fieldName = first+last;
			}
			if(fieldName.length()<=3){
				return fieldName.toLowerCase();
			}
		}catch (Exception e){
			System.out.println(this.cname+"格式化名称出现异常！");
			return this.cname;
		}
		return fieldName;
	}
	public void setName(String name) {
		this.name = name;
	}

	public void setType(String type) {
		this.type = type;
	}
	public String getTypeName() {
		return typeName;
	}

	public void setTypeName(String typeName) {
		this.typeName = typeName;
	}

	public String getCname() {
		return cname;
	}

	public void setCname(String cname) {
		this.cname = cname;
	}

	public String getTypeNum() {
		return typeNum;
	}

	public void setTypeNum(String typeNum) {
		this.typeNum = typeNum;
	}

	public Integer getStatus() {
		return status;
	}

	public void setStatus(Integer status) {
		this.status = status;
	}

	public String getType() {
		String type = "String";
		int id = Integer.parseInt(this.typeNum);
		switch (id) {
			case -6:
			case 5:
			case 4:
			case -5:
			case 3:
				type = "Integer";
				break;
			case 1:
			case -1:
			case 12:
				type = "String";
				break;
			case 7:
				type="Float";
				break;
			case 8:
				type="Double";
				break;
			case 91:
				type = "Date";
				break;
			case 92:
				type = "Time";
				break;
			case 93:
				type = "Timestamp";
				break;
			default:
				type = "未知";
				break;
		}
		return type;
	}
}
